<?php

namespace App\Admin\Controllers;

use App\Constant\Enum;
use App\Models\App;
use App\Models\Notice;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class NoticeController extends AdminController
{
    protected $type;


    public function __construct($userId = 0)

    {

        $this->type = ['首页弹窗','首页文字'];

    }
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Notice(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('remark');
            $grid->column('status')->using([
                Enum::STATUS_ENABLED => '启用',
                Enum::STATUS_DISABLED => '禁用',
            ])->label([
                Enum::STATUS_ENABLED => 'success',
                Enum::STATUS_DISABLED => 'danger',
            ])->sortable();
            $grid->column('type')->using( $this->type);

            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->like('remark');
            });

            $grid->fixColumns(3, -1);
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Notice(), function (Show $show) {
            $show->field('id');
            $show->field('remark');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Notice(), function (Form $form) {
            $form->display('id');
            $form->text('name');
            $form->textarea('remark');
            $form->radio('status')->options(Enum::getSelectableStatusExplains())->default(Enum::STATUS_ENABLED)->required();
            $form->radio('type')->options($this->type);

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
